package com.mit.web.business.proxy
{
	import com.mit.web.business.remote.BaseService;
	import com.mit.web.business.remote.IInvokeResponder;
	import com.mit.web.config.Constants;
	import com.mit.web.config.DisplayConfiguration;
	import com.mit.web.vo.purchase.ColorStyleVO;
	import com.mit.web.vo.purchase.InquiryItemVO;
	import com.mit.web.vo.purchase.InquiryTaskVO;
	import com.mit.web.vo.purchase.MaterialVO;
	import com.mit.web.vo.purchase.POItemVO;
	import com.mit.web.vo.purchase.POVO;
	import com.mit.web.vo.purchase.SupplierVO;
	
	import mx.collections.ArrayCollection;

	public class PurchaseProxy extends BaseService
	{
		private static var me:PurchaseProxy;
		public function PurchaseProxy()
		{
			super(Constants.REMOTE_OBJECT_PURCHASE);
			if(me != null)
				throw new Error("Only one instance of this class is allowed, use getInstance() insteadof the constructor.");
		}
		
		public static function getInstance():PurchaseProxy{
			if(me == null)
				me = new PurchaseProxy();
			return me;
		} 
		
		public function saveSupplier(supplier:SupplierVO):IInvokeResponder{
			return invoke("saveSupplier", supplier);
		}
		
		public function getPagedSuppliers(pageNo:int, searchKey:String = null):IInvokeResponder{
			return invoke("retrievePagedSuppliers", searchKey, pageNo, DisplayConfiguration.getInstance().PAGE_SIZE);
		}
		
		public function getSupplierCount(searchKey:String = null):IInvokeResponder{
			return invoke("retrieveSupplierCount", searchKey);
		}	

		public function getSuppliers(searchName:String = null):IInvokeResponder{
			return invoke("retrieveSupplierBasicInfo", searchName);
		}		

		public function getSupplierProducts(supplierId:int, activeInd:String = null):IInvokeResponder{
			return invoke("retrieveMaterials", supplierId, activeInd);
		}
		public function saveSupplierProduct(product:MaterialVO):IInvokeResponder{
			return invoke("saveMaterial", product);
		}
		public function getProductColors(productId:int, activeInd:String = null):IInvokeResponder{
			return invoke("retrieveColorStyles", productId, activeInd);
		}
		public function saveProductColor(color:ColorStyleVO):IInvokeResponder{
			return invoke("saveColorStyle", color);
		}	
		
		public function getPagedInquiryTasks(pageNo:int, styleCode:String = null, taskState:String = null):IInvokeResponder{
			return invoke("retrievePagedInquiryTasks", styleCode, taskState, pageNo, DisplayConfiguration.getInstance().PAGE_SIZE);
		}
		public function getInquiryTaskCount(styleCode:String = null, taskState:String = null):IInvokeResponder{
			return invoke("retrieveInquiryTaskCount", styleCode, taskState);
		}
		public function getInquiryItems(taskId:int):IInvokeResponder{
			return invoke("retrieveInquiryItems", taskId);
		}
		public function saveInquiryItem(item:InquiryItemVO):IInvokeResponder{
			return invoke("saveInquiryItem", item);
		}
		public function saveInquiryTask(task:InquiryTaskVO):IInvokeResponder{
			return invoke("saveInquiryTask", task);
		}
		public function getPagedPO(pageNo:int, styleCode:String = null, code:String=null, supplierId:int=0, dateFrom:Date=null, dateTo:Date=null, state:String = null):IInvokeResponder{
			return invoke("retrievePagedPO", styleCode, code, supplierId,dateFrom, dateTo, state, pageNo, DisplayConfiguration.getInstance().PAGE_SIZE);
		}
		
		public function getPOCount( styleCode:String = null,code:String=null, supplierId:int=0, dateFrom:Date=null, dateTo:Date=null, state:String = null):IInvokeResponder{
			return invoke("retrievePOCount", styleCode, code, supplierId,dateFrom, dateTo, state);
		}
		
		public function getPendingPurchaseItems():IInvokeResponder{
			return invoke("retrievePendingPurchaseItems");
		}
		
		public function getInquiryInfoByItem(fabId:int, prodColorId:int = 0):IInvokeResponder{
			return invoke("retrieveInquiryInfo",fabId, prodColorId);
		}
		
		public function bulkCreatePO(po:POVO):IInvokeResponder{
			return invoke("bulkCreatePO", po);
		}
		
		public function getMergedPOItems(poId:int):IInvokeResponder{
			return invoke("retrieveMergedPOItems", poId);
		}
		
		public function updatePOState(poId:int, state:String):IInvokeResponder{
			return invoke("updatePOState", poId, state);
		}
		
		public function deletePO(poId:int):IInvokeResponder{
			return invoke("deletePO", poId);
		}
		
		public function getEditablePOItems(item:POItemVO):IInvokeResponder{
			return invoke("retrieveEditablePOItems", item);
		}
		
		public function savePO(po:POVO):IInvokeResponder{
			return invoke("savePO", po);
		}
	}
}